@model Eqwww.Web.Areas.SystemManage.Models.User.EditViewModel
@inject Eqwww.Config.IAppConfigProvider AppConfigProvider
@{
    var appConfig=AppConfigProvider.Load();

    ViewData["Title"] = "修改用户";
    Layout = "~/Views/Shared/_ManageFormLayout.cshtml";
}


<form id="form1" class="mdui-m-t-3 mdui-m-b-3">
    <div asp-validation-summary="ModelOnly" class="mdui-textfield-error"></div>
    <input asp-for="Id" type="hidden" />
    <div class="mdui-container">

        <div class="mdui-row">
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="UserName" class="mdui-textfield-label"></label>
                    <input asp-for="UserName" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="UserName" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="RealName" class="mdui-textfield-label"></label>
                    <input asp-for="RealName" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="RealName" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Contact" class="mdui-textfield-label"></label>
                    <input asp-for="Contact" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Contact" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Email" class="mdui-textfield-label"></label>
                    <input asp-for="Email" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Email" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield">
                    <label asp-for="UserType" class="mdui-textfield-label"></label>
                    <select asp-for="UserType" class="mdui-textfield-input mdui-color-grey-100" asp-items="@Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.Identity.UserType))">
                        <option value="">==请选择==</option>
                    </select>
                    <i class="mdui-icon material-icons" style="position:absolute;right:0;">arrow_drop_down</i>
                    <span asp-validation-for="UserType" class="mdui-textfield-error"></span>
                </div>

            </div>

            <div id="Password_Box" class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Password" class="mdui-textfield-label">新密码（不修改密码则留空）</label>
                    <input asp-for="Password" type="password" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Password" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div id="RepeatPassword_Box" class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="RepeatPassword" class="mdui-textfield-label"></label>
                    <input asp-for="RepeatPassword" type="password" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="RepeatPassword" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="SortCode" class="mdui-textfield-label"></label>
                    <input asp-for="SortCode" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="SortCode" class="mdui-textfield-error"></span>
                </div>
            </div>


            

            <style type="text/css">

                .eq-avatar-choose-box img {
                    width: 64px;
                    cursor: pointer;
                }

                .eq-avatar-choosed-box img {
                    width: 128px;
                }
            </style>
            <div class="mdui-col-xs-12">
                <div class="mdui-typo-body-2">用户头像</div>
                <div class="eq-avatar-choose-box">
                    <img src="~/images/avatars/default.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-11.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-12.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-13.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-14.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-15.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-16.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-17.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-18.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-19.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-20.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-21.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-22.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-23.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-24.png" class="mdui-img-circle" />
                </div>
                <div class="eq-avatar-choosed-box">
                    <img src="@Model.Avatar" class="mdui-img-circle" />
                </div>
                <input type="hidden" asp-for="Avatar" />
                @if (appConfig.CanUseCustomAvatar)
                {
                    <div>
                        <a href="javascript:;" onclick="btn_customavatar()" class="mdui-btn mdui-text-color-theme mdui-ripple">
                            使用自定义头像 <i class="mdui-icon material-icons">arrow_forward</i>
                        </a>
                    </div>
                }
            </div>
        </div>

    </div>
</form>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

    <script>

        var userid=$.request('id');

        $(function () {
            //$('#Avatar').val('/images/avatars/default.png');
            $('.eq-avatar-choose-box img').click(function () {
                var $this = $(this);
                $('.eq-avatar-choosed-box img').attr('src', $this.attr('src'));
                $('#Avatar').val($this.attr('src'));
            });


            var userType = '@Model.UserType';

            if (userType == 'RTX') {
                $('#Password').val('');
                $('#RepeatPassword').val('');
                $('#Password_Box').hide();
                $('#RepeatPassword_Box').hide();
            }

            $('#UserType').change(function () {
                var $this = $(this);
                if ($this.val() == "1") {
                    $('#Password').val('');
                    $('#RepeatPassword').val('');
                    $('#Password_Box').hide();
                    $('#RepeatPassword_Box').hide();
                }
                else {
                    $('#Password_Box').show();
                    $('#RepeatPassword_Box').show();
                }
            });
        });

        function btn_customavatar()
        {
            $.modalOpen({
                id: 'customavatar',
                title: '自定义头像',
                url: '/SystemManage/User/CustomAvatar?id=' + userid,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    var index = top.layer.getFrameIndex(window.name);
                    top.frames[iframeId].submitForm(index);
                }
            });
        }


        function submitForm() {

            if (!$("#form1").valid()) {
                return false;
            }

            if ($('#UserType').val() == '0') {
                
                if ($('#Password').val() != $('#RepeatPassword').val()) {
                    $.modalAlert('【本地账户】类型【密码】和【重复密码】输入不一致！');
                    return false;
                }
            }
            var postData = $('#form1').formSerialize();

            $.submitForm({
                url: "/SystemManage/User/Edit",
                param: postData,
                success: function () {
                    $.currentWindow().location.reload();
                }
            });

        };
    </script>
}

